package com.genius.action;

import java.util.Date;
import java.util.List;

import com.genius.core.manager.StudentManager;
import com.genius.model.StudentPayment;
import com.genius.util.DateUtil;
import com.opensymphony.xwork.ActionSupport;

/**
 * 
 * TODO Description
 * 
 * @author Manish R [manish_rathi2001@yahoo.com]
 * @version 1.0
 */
public class StudentPaymentAction extends ActionSupport
{
 
    /**
     * 
     */
    private static final long serialVersionUID = -1068893968081759707L;

    private StudentPayment studentPayment = null;

    StudentManager studentManager = null;
    
    private String studentId = null;
    
    private String chequeDateStr = null;
    
    private String paymentDateStr = null;
    
    private List studentPaymentList = null;
    
            
            
        /**
         * @return Returns the student.
         */
        public StudentPayment getStudentPayment()
        {
            return this.studentPayment;
        }

        /**
         * @param student The student to set.
         */
        public void setStudentPayment(StudentPayment studentPayment)
        {
            this.studentPayment = studentPayment;
        }

        public StudentPaymentAction()
        {
            //this.studentPayment = new StudentPayment();
        }

        /**
         * @see com.opensymphony.xwork.ActionSupport#execute()
         */
        public String showAddStudentPaymentForm() throws Exception
        {
            //Returns page with student entry form
        	this.studentPayment = new StudentPayment();
        	studentPayment.setPaymentDate(new Date());
        	studentPayment.setStudentId(studentId);
            return this.SUCCESS;
        }
        
        /**
         * @see com.opensymphony.xwork.ActionSupport#execute()
         */
        public String addStudentPayment() throws Exception

        {
            // Add new student to database.
        	studentPayment.setChequeDate(DateUtil.stringToDate(chequeDateStr));
        	studentPayment.setPaymentDate(DateUtil.stringToDate(paymentDateStr));
        	studentManager.addStudentPayment(studentPayment);
        	studentPaymentList = studentManager.getStudentPaymentDetails(studentPayment.getStudentId());
            return this.SUCCESS;
        }

        /**
         * @return Returns the studentManager.
         */
        public StudentManager getStudentManager()
        {
            return studentManager;
        }

        /**
         * @param studentManager The studentManager to set.
         */
        public void setStudentManager(StudentManager studentManager)
        {
            this.studentManager = studentManager;
        }

		public String getChequeDateStr() {
			return DateUtil.dateToString(studentPayment.getChequeDate());
		}

		public void setChequeDateStr(String value) {
			this.chequeDateStr = value;
			studentPayment.setChequeDate(DateUtil.stringToDate(value));
		}

		public String getPaymentDateStr() {
			return DateUtil.dateToString(studentPayment.getPaymentDate());
		}

		public void setPaymentDateStr(String value) {
			this.paymentDateStr = value;
			studentPayment.setPaymentDate(DateUtil.stringToDate(value));
		}

		public String getStudentId() {
			return studentId;
		}

		public void setStudentId(String studentId) {
			this.studentId = studentId;
		}

		public List getStudentPaymentList() {
			return studentPaymentList;
		}

		public void setStudentPaymentList(List studentPaymentList) {
			this.studentPaymentList = studentPaymentList;
		}

}
